import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/homePage/login.vue"),
    meta: { hidden: true },
  },
  {
    path: "/homePage",
    component: () => import("@/views/homePage/index.vue"),
    meta: { hidden: true },
  },
  {
    path: "/elogin",
    component: () => import("@/views/homePage/ELogin.vue"),
    meta: { hidden: true },
  },
  {
    path: "/requiredReading",
    component: () => import("@/views/homePage/requiredReading.vue"),
    meta: { hidden: true },
  },
  {
    path: "/exam",
    component: () => import("@/views/examSystem/exam.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/systemManagement/eventManagement",
    meta: { hidden: true },
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "dashboard",
          affix: true,
          alwaysShow: false,
          hidden: true,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },
  {
    path: "/systemManagement",
    component: Layout,
    meta: {
      title: "赛事管理",
      hidden: false,
    },
    children: [
      {
        path: "eventManagement",
        component: () =>
          import("@/views/systemManagement/eventManagement/index.vue"),
        name: "EventManagement",
        meta: {
          title: "赛项管理",
          icon: "dept",
          hidden: false,
        },
      },
      {
        path: "examPaperManagement",
        component: () =>
          import("@/views/systemManagement/examPaperManagement/index.vue"),
        name: "ExamPaperManagement",
        meta: {
          title: "试卷管理",
          hidden: false,
          icon: "dept",
        },
      },
      {
        path: "questionManagement",
        component: () =>
          import(
            "@/views/systemManagement/examPaperManagement/questionManagement.vue"
          ),
        name: "QuestionManagement",
        meta: {
          title: "试题",
          hidden: true,
          icon: "dept",
        },
      },
      // {
      //   path: "addTestQuestions",
      //   component: () =>
      //     import(
      //       "@/views/systemManagement/examPaperManagement/addTestQuestions.vue"
      //     ),
      //   name: "AddTestQuestions",
      //   meta: {
      //     title: "新增试题",
      //     hidden: true,
      //     icon: "dept",
      //   },
      // },

      {
        path: "examProgress",
        component: () =>
          import("@/views/systemManagement/examProgress/index.vue"),
        name: "ExamProgress",
        meta: {
          title: "考试进度",
          icon: "dept",
          hidden: false,
        },
      },
      {
        path: "examProgressDetails",
        component: () =>
          import("@/views/systemManagement/examProgress/details.vue"),
        name: "ExamProgressDetails",
        meta: {
          title: "进度详情",
          icon: "dept",
          hidden: true,
        },
      },
      // {
      //   path: "groupManagement",
      //   component: () =>
      //     import("@/views/systemManagement/groupManagement/index.vue"),
      //   name: "GroupManagement",
      //   meta: {
      //     title: "组别管理",
      //     icon: "dept",
      //     hidden: false,
      //   },
      // },
      {
        path: "theoreticalScore",
        component: () =>
          import("@/views/systemManagement/theoreticalScore/index.vue"),
        name: "TheoreticalScore",
        meta: {
          title: "理论成绩",
          icon: "dept",
          hidden: false,
        },
      },
      {
        path: "examPapersDetails",
        component: () =>
          import(
            "@/views/systemManagement/theoreticalScore/examPapersDetails.vue"
          ),
        name: "ExamPapersDetails",
        meta: {
          title: "考试试卷",
          hidden: true,
        },
      },
    ],
  },
  {
    path: "/teamManagement",
    component: Layout,
    meta: {
      title: "赛队管理",
      hidden: false,
      icon: "tree",
    },
    children: [
      {
        path: "list",
        component: () =>
          import("@/views/systemManagement/teamManagement/index.vue"),
        name: "TeamManagement",
        meta: {
          title: "赛队管理",
          hidden: false,
          icon: "dept",
        },
      },
      {
        path: "teamStatistics",
        component: () =>
          import("@/views/systemManagement/teamManagement/teamStatistics.vue"),
        name: "TeamStatistics",
        meta: {
          title: "队伍统计",
          hidden: false,
          icon: "dept",
        },
      },
    ],
  },
  // {
  //   path: "/examPaperManagement",
  //   component: Layout,
  //   meta: {
  //     title: "试卷管理",
  //     hidden: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () =>
  //         import("@/views/systemManagement/examPaperManagement/index.vue"),
  //       name: "ExamPaperManagement",
  //       meta: {
  //         title: "试卷管理",
  //         hidden: false,
  //         icon: "document",
  //       },
  //     },
  //     {
  //       path: "questionManagement",
  //       component: () =>
  //         import(
  //           "@/views/systemManagement/examPaperManagement/questionManagement.vue"
  //         ),
  //       name: "QuestionManagement",
  //       meta: {
  //         title: "试题",
  //         hidden: true,
  //         icon: "dept",
  //       },
  //     },
  //     {
  //       path: "addTestQuestions",
  //       component: () =>
  //         import(
  //           "@/views/systemManagement/examPaperManagement/addTestQuestions.vue"
  //         ),
  //       name: "AddTestQuestions",
  //       meta: {
  //         title: "新增试题",
  //         hidden: true,
  //         icon: "dept",
  //       },
  //     },
  //   ],
  // },
  {
    path: "/userManagement",
    component: Layout,
    meta: {
      title: "系统管理",
      hidden: false,
      icon: "setting",
    },
    children: [
      {
        path: "index",
        component: () =>
          import("@/views/systemManagement/userManagement/index.vue"),
        name: "UserManagement",
        meta: {
          title: "用户管理",
          hidden: false,
          icon: "dept",
        },
      },
      {
        path: "groupManagement",
        component: () =>
          import("@/views/systemManagement/groupManagement/index.vue"),
        name: "GroupManagement",
        meta: {
          title: "组别管理",
          icon: "dept",
          hidden: false,
        },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
